// eslint-disable-next-line require-jsdoc
export function getLocalItem(key) {
  const data = localStorage.getItem(key)
  if (!data) {
    return null
  }
  try {
    return JSON.parse(data)
  } catch (e) {
    console.error(e)
    return null
  }
}

export function setLocalItem(key, value) {
  if (value === undefined || value === null) {
    localStorage.removeItem(key)
  } else {
    localStorage.setItem(key, JSON.stringify(value))
  }
}